package com.example.controller;

import com.example.common.Result;
import com.example.entity.Archive;
import com.example.service.ArchiveService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 档案 和 档案审批 接口
 **/
@RestController
@RequestMapping("/Archive")
public class ArchiveController {

    @Resource
    private ArchiveService archiveService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody Archive archive) {
        archiveService.add(archive);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        archiveService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        archiveService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody Archive archive) {

        archiveService.updateById(archive);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Archive archive = archiveService.selectById(id);
        return Result.success(archive);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(Archive archive ) {
        List<Archive> list = archiveService.selectAll(archive);
        return Result.success(list);
    }
    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(Archive archive,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Archive> page = archiveService.selectPage(archive, pageNum, pageSize);
        return Result.success(page);
    }

    /*审批记录分页查询*/
    @GetMapping("/selectPage2")
    public Result selectPage2(Archive archive,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Archive> page = archiveService.selectPage2(archive, pageNum, pageSize);
        return Result.success(page);
    }
    /*待审批分页查询*/
    /*审批记录分页查询*/
    @GetMapping("/selectPage3")
    public Result selectPage3(Archive archive,
                              @RequestParam(defaultValue = "1") Integer pageNum,
                              @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Archive> page = archiveService.selectPage3(archive, pageNum, pageSize);
        return Result.success(page);
    }
}